package fhp.hlhj.giantfold.activity.cameraScan

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.activity.camera.Camera2Aty
import fhp.hlhj.giantfold.adapter.MerchantGridAdp
import fhp.hlhj.giantfold.customView.FullyGridLayoutManager
import fhp.hlhj.giantfold.javaBean.MerchantBean
import fhp.hlhj.giantfold.network.Urls
import fhp.hlhj.giantfold.utils.LogUtil
import fhp.hlhj.giantfold.utils.MyUtils
import kotlinx.android.synthetic.main.activity_seller_detail_aty.*
import java.util.*

class MerchantDetailAty : BaseActivity() {
    private lateinit var gridAdp:BaseQuickAdapter<String,BaseViewHolder>
    private val datas=ArrayList<String>()
    private lateinit var bean:MerchantBean.DataBean
    override fun getContentId(): Int {
        return R.layout.activity_seller_detail_aty
    }

    override fun initView() {
        bean = intent.getSerializableExtra("data") as MerchantBean.DataBean
        tvTitle.text=bean.name
        gridAdp= object :BaseQuickAdapter<String,BaseViewHolder>(R.layout.merchant_img_item,datas){
            override fun convert(helper: BaseViewHolder?, item: String?) {
                val img = helper?.getView<ImageView>(R.id.img)
                Glide.with(mContext).load(Urls.BaseUrl+bean.savepath0+item).asBitmap().dontAnimate().placeholder(R.mipmap.exp2).into(img)
            }
        }
        gdView.adapter=gridAdp
        gdView.layoutManager=FullyGridLayoutManager(this,3)
        datas.add(bean.savename1)
        datas.add(bean.savename2)
        datas.add(bean.savename3)
        datas.add(bean.savename4)
        datas.add(bean.savename5)
        datas.add(bean.savename6)
        LogUtil.logi("数据的大小为${datas.toString()}")
        gridAdp.notifyDataSetChanged()

        /*开启时间*/
        val timer = Timer()
        val task = object:TimerTask(){
            override fun run() {
                gdView?.post(Runnable {
                    val endTimestamp = MyUtils.dateToStamp(bean.end_time)
                    val time = (endTimestamp.toLong() - System.currentTimeMillis())/1000
                    val day=time/60/60/24
                    val hour = time / (60 * 60)-day*24
                    val min = time % 3600 /60
                    var sec=time%3600% 60
                    tvDay?.text="距离结束还有${day}天"
                    tvH?.text=hour.toString()
                    tvMin?.text=min.toString()
                    tvSec?.text=sec.toString()
                })
            }
        }
        timer.schedule(task,0,1000)
    }
    override fun initListener() {
        btCam.setOnClickListener {
            val intent = Intent(this, Camera2Aty::class.java)
            intent.putExtra("mid",bean.id)
            startActivity(intent)
        }
    }
}
